package com.canbot.u05.activity.customvoice.tool

import android.app.Dialog
import android.content.Context
import android.graphics.Color
import android.graphics.Point
import android.graphics.drawable.ColorDrawable
import android.os.Bundle
import android.view.View

import com.canbot.u05.R
import com.canbot.u05.activity.customvoice.bean.CustomDialogExcelDatas
import com.canbot.u05.activity.loge
import kotlinx.android.synthetic.main.custom_dialog_detalis_view.*

/**
 * CustomDialogDetailsView
 *
 * @author Liu.Heng
 * @date 2019/6/4
 */
class CustomDialogDetailsView(context: Context, private val customDialogExcelDatas: CustomDialogExcelDatas) : Dialog(context), View.OnClickListener {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.custom_dialog_detalis_view)
        setCanceledOnTouchOutside(false)
        /**设置弹窗的宽度*/
        val m = window?.windowManager
        val d = m?.defaultDisplay
        val p = window?.attributes
        val size = Point()
        d?.getSize(size)
        p?.width = size.x
        p?.height = size.y
        window?.attributes = p
        window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        hideBottomUIMenu()
        initView()
    }

    private fun initView() {
        back_view.setOnClickListener(this)
        val stringBuffer = StringBuffer()

        customDialogExcelDatas.listQsBean.forEach {
            stringBuffer.append(it.question).append("\n")
        }
        questions_text.text = stringBuffer
    }

    /**
     * 隐藏虚拟按键，并且全屏
     */
    private fun hideBottomUIMenu() {
        val attributes = window?.attributes
        attributes?.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        window?.attributes = attributes
        window?.decorView?.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        window?.decorView?.setOnSystemUiVisibilityChangeListener { _ ->
            var uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE or
                    /**布局位于状态栏下方*/
                    View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION or
                    /**全屏*/
                    View.SYSTEM_UI_FLAG_FULLSCREEN or
                    /**隐藏导航栏*/
                    View.SYSTEM_UI_FLAG_HIDE_NAVIGATION or
                    View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            uiOptions = uiOptions or 0x00001000
            window?.decorView?.systemUiVisibility = uiOptions
        }
    }

    override fun onClick(view: View) {
        loge("$view")
        this.dismiss()
    }
}
